//
//  ZMJMusicsTool.m
//  Z-QQMusic
//
//  Created by zmj on 15/11/5.
//  Copyright © 2015年 zmj. All rights reserved.
//

#import "ZMJMusicsTool.h"
#import "ZMJMusic.h"
#import "MJExtension.h"
@implementation ZMJMusicsTool
static NSArray *musics_;
static ZMJMusic *playingMusic_;
/**
 *  初始化歌曲信息数组
 */
+ (void)initialize {
    if (musics_ == nil) {
        musics_ = [ZMJMusic mj_objectArrayWithFilename:@"Musics.plist"];
    }
}

/**返回当前播放歌曲信息*/
+ (ZMJMusic *)playingMusic {
    
    if (playingMusic_ == nil) { // 如果没有设置过,默认返回数组中第一首歌曲信息
        playingMusic_ = musics_[0];
    }
    return playingMusic_;
}

- (void)setPlayingMusic:(ZMJMusic *)playingMusic {
 
    playingMusic_ = playingMusic;
}

- (ZMJMusic *)playingMusic {
    return playingMusic_;
}

/**下一首歌曲*/
+ (ZMJMusic *)nextMusic {
    NSInteger currentMusicIndex = [musics_ indexOfObject:playingMusic_];
    NSInteger nextMusicIndex = currentMusicIndex + 1;
    if (nextMusicIndex > musics_.count - 1) {
        nextMusicIndex = 0;
    }
    playingMusic_ = musics_[nextMusicIndex];
    return playingMusic_;
}
/**上一首歌曲*/
+ (ZMJMusic *)previousMusic {
    NSInteger currentMusicIndex = [musics_ indexOfObject:playingMusic_];
    NSInteger previousMusicIndex = currentMusicIndex - 1;
    if (previousMusicIndex < 0) {
        previousMusicIndex = musics_.count - 1;;
    }
    playingMusic_ = musics_[previousMusicIndex];
    return playingMusic_;
}

@end
